// 如果不是大数的情况
// Array.prototype.unshift. parseInt
let str = '123';
let res = parseInt(str);
// 2. +
let res1 = +str;
// 3. ~~
let res2 = ~~str;
// 4. Number
let res3 = Number(str);


// 如果是大数的情况
let res4 = BigInt(str);
// 类似于parseInt的底层实现
function transfrom(str){
    let sum = 0;
    for(let i = 0; i < str.length; ++i){
        const value = str.charAt(i);
        if(value < "0" || value > "9") break;
        sum *= 10;
        sum += strToNumber(value);
    }
    function strToNumber(char){
        switch (char) {
            case "1":
                return 1
            case "2":
                return 2
            case "3":
                return 3
            case "4":
                return 4
            case "5":
                return 5
            case "6":
                return 6
            case "7":
                return 7
            case "8":
                return 8
            case "9":
                return 9
            default:
                return 0
        }
    }
    return sum;
}

console.log(transfrom("12314sadfa"))
